﻿using Supore.APP.UI.Controls.Notify;
using SuporeSliplampApp.Models;
using SuporeSliplampApp.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SuporeSliplampApp.Views
{
    /// <summary>
    /// NewUserWindow.xaml 的交互逻辑
    /// </summary>
    public partial class NewUserWindow : Window
    {
        AddUserService service;
        private UserModel _user;
        public NewUserWindow()
        {
            InitializeComponent();
        }

        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (p_pwd.Text.Trim() != (p_pwd2.Text.Trim()))
            {
                MessageBox.Show("两次密码输入不一致，请重新输入!", "提醒");
                p_pwd.Clear();
                p_pwd2.Clear();
                p_pwd.Focus();
                return;
            }
            _user = new UserModel();
            service = new AddUserService();
            _user.UserName = this.p_name.Text.Trim();
            _user.Password = this.p_pwd.Text.Trim();
            if (!service.AddUser(_user))
            {
                LayUINotify.ShowInfo("保存失败！");
                return;
            }
            else
            {
                LayUINotify.ShowSuccess("保存成功！");
                this.Close();

            }



        }

        private void closeBtn_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
